package top.hekun.study;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.DocumentRenderData;
import com.deepoove.poi.data.Documents;
import com.deepoove.poi.data.Paragraphs;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 无模板创建示例
 * @Author: 贺坤
 * @Date: 2023/6/11 16:54
 */
public class NoTemplate {
    public static void main(String[] args) throws IOException {
        String text = "this a paragraph";
        DocumentRenderData data = Documents.of()
                .addParagraph(Paragraphs.of(text).create())
                .addDocument(Documents.of().addParagraph(Paragraphs.of("小坤坤").create()).create())
                .create();

        XWPFTemplate template = XWPFTemplate.create(data);

        File docPath = getFilePath("NoTemplateResult.docx");
        template.writeAndClose(new FileOutputStream(docPath));
    }
    private static File getFilePath(String name){

        File filePath = new File(new File(new File(new File(new File(System.getProperty("user.dir"), "poi-tl"), "src"), "main"), "resources"), name);
        return filePath;
    }
}
